package com.web.function;


import com.entity.Function;
import com.entity.RoleInfo;
import com.entity.UserInfo;
import com.service.FunctionService;
import com.service.RoleService;
import com.service.UserService;
import com.service.impl.FunctionServiceImpl;
import com.service.impl.RoleServiceImpl;
import com.service.impl.UserServiceImpl;
import com.sys.utils.Mark;
import com.sys.utils.RequestBeanUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class FunctionAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public FunctionAddServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher(Mark.URL_SYSTEM_FUNCTION + "function_add.jsp")
				.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		//获取页面数据 自动存放发到UserInfo对象
		Function function = RequestBeanUtils.requestToBean(request, Function.class);
		
		//权限管理的业务逻辑类
		FunctionService service = new FunctionServiceImpl();
		
		System.out.println(function);
		boolean mark =  service.add(function);
		if(mark){
			request.setAttribute(Mark.ERROR_INFO,"权限信息添加成功！");
		}else{
			request.setAttribute(Mark.ERROR_INFO,"权限信息添加失败！");
		}
		
		request.getRequestDispatcher("FunctionQueryServlet")
		.forward(request, response);
	}
}
